package com.shop.operator.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.shop.domain.PageResult;
import com.shop.mapper.ContentMapper;
import com.shop.model.Content;
import com.shop.operator.service.ContentService;

@Service("contentService")
public class ContentServiceBean implements ContentService {

	@Resource
	private ContentMapper contentMapper;
	@Override
	public PageResult findContent(int page, int size) throws Exception {
		PageHelper.startPage(page, size);//先把分页引进来
		
		Page<Content> pageContent = (Page<Content>) this.contentMapper.selectByExample(null);
		
		
		return new PageResult(pageContent.getTotal(),pageContent.getResult());
	}
	
	@Override
	public boolean add(Content content) throws Exception {
		
		int count = this.contentMapper.insertSelective(content); 
		return count>0;
	}
	

	@Override
	public Content findOneContent(Long id) throws Exception {
		
			return  this.contentMapper.selectByPrimaryKey(id);
	}

	@Override
	public boolean update(Content content) throws Exception {
		
		int count = this.contentMapper.updateByPrimaryKeySelective(content);
		
		return count>0;
	}

	@Override
	public boolean delete(Long[] ids) throws Exception {
		int count = 0;
		for(Long id:ids){
			count = this.contentMapper.deleteByPrimaryKey(id);
		}
		return count>0;
	}


}
